package logic

import (
	"context"
	"errors"
	"person/model/mysql"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserShowLogic) UserShow(in *personrpc.UserShowRequest) (*personrpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User
	err := user.UserShow(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("当前用户不存在，请更换")
	}

	return &personrpc.UserShowResponse{
		UserId:    int64(user.ID),
		Account:   user.Account,
		Password:  user.Password,
		HeadImage: user.HeadImage,
		Name:      user.Name,
	}, nil
}
